package com.dc.cameraxtest

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.dc.cameraxtest.adapter.PagesAdapter
import com.dc.cameraxtest.databinding.ActivityPagesBinding

class PagesActivity : AppCompatActivity() {


    private val pageItems = listOf("摄像头预览", "OpenCv灰度预览", "中文识别", "边缘检测", "文档校正")

    private lateinit var viewBinding: ActivityPagesBinding
    companion object {
        private const val TAG = "PagesActivity"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_pages)

        initView()
    }

    private fun initView() {
        viewBinding = ActivityPagesBinding.inflate(layoutInflater)
        setContentView(viewBinding.root)

        viewBinding.pageRv.layoutManager = LinearLayoutManager(this)

        val adapter = PagesAdapter(pageItems, object : PagesAdapter.OnItemClickListener{
            override fun onItemClick(position: Int) {
                Log.e(TAG, "onItemClick: position = $position", )
                when(position) {
                    0 -> startActivity(Intent(this@PagesActivity, MainActivity::class.java))
                    1 -> startActivity(Intent(this@PagesActivity, OpenCvActivity::class.java))
                    2 -> startActivity(Intent(this@PagesActivity, OcrActivity::class.java))
                    3 -> startActivity(Intent(this@PagesActivity, BorderDetectionActivity::class.java))
                    4 -> startActivity(Intent(this@PagesActivity, DocActivity::class.java))
                }
            }
        } )
        viewBinding.pageRv.adapter = adapter
    }
}